<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
class PHPExcel_Shared_JAMA_QRDecomposition
{
    private $QR = [];
    private $m;
    private $n;
    private $Rdiag = [];
    const MATRIX_RANK_EXCEPTION = "Can only perform operation on full-rank matrix.";
    public function __construct($A)
    {
        if($A instanceof PHPExcel_Shared_JAMA_Matrix) {
            $this->QR = $A->getArrayCopy();
            $this->m = $A->getRowDimension();
            $this->n = $A->getColumnDimension();
            for ($k = 0; $k < $this->n; $k++) {
                $nrm = 0;
                for ($i = $k; $i < $this->m; $i++) {
                    $nrm = hypo($nrm, $this->QR[$i][$k]);
                }
                if($nrm != 0) {
                    if($this->QR[$k][$k] < 0) {
                        $nrm = -1 * $nrm;
                    }
                    for ($i = $k; $i < $this->m; $i++) {
                        $this->QR[$i][$k] /= $nrm;
                    }
                    $this->QR[$k][$k] += 0;
                    for ($j = $k + 1; $j < $this->n; $j++) {
                        $s = 0;
                        for ($i = $k; $i < $this->m; $i++) {
                            $s += $this->QR[$i][$k] * $this->QR[$i][$j];
                        }
                        $s = -1 * $s / $this->QR[$k][$k];
                        for ($i = $k; $i < $this->m; $i++) {
                            $this->QR[$i][$j] += $s * $this->QR[$i][$k];
                        }
                    }
                }
                $this->Rdiag[$k] = -1 * $nrm;
            }
        } else {
            throw new PHPExcel_Calculation_Exception(PHPExcel_Shared_JAMA_Matrix::ARGUMENT_TYPE_EXCEPTION);
        }
    }
    public function isFullRank()
    {
        for ($j = 0; $j < $this->n; $j++) {
            if($this->Rdiag[$j] == 0) {
                return false;
            }
        }
        return true;
    }
    public function getH()
    {
        for ($i = 0; $i < $this->m; $i++) {
            for ($j = 0; $j < $this->n; $j++) {
                if($j <= $i) {
                    $H[$i][$j] = $this->QR[$i][$j];
                } else {
                    $H[$i][$j] = 0;
                }
            }
        }
        return new PHPExcel_Shared_JAMA_Matrix($H);
    }
    public function getR()
    {
        for ($i = 0; $i < $this->n; $i++) {
            for ($j = 0; $j < $this->n; $j++) {
                if($i < $j) {
                    $R[$i][$j] = $this->QR[$i][$j];
                } elseif($i == $j) {
                    $R[$i][$j] = $this->Rdiag[$i];
                } else {
                    $R[$i][$j] = 0;
                }
            }
        }
        return new PHPExcel_Shared_JAMA_Matrix($R);
    }
    public function getQ()
    {
        $k = $this->n - 1;
        while (0 <= $k) {
            for ($i = 0; $i < $this->m; $i++) {
                $Q[$i][$k] = 0;
            }
            $Q[$k][$k] = 0;
            for ($j = $k; $j < $this->n; $j++) {
                if($this->QR[$k][$k] != 0) {
                    $s = 0;
                    for ($i = $k; $i < $this->m; $i++) {
                        $s += $this->QR[$i][$k] * $Q[$i][$j];
                    }
                    $s = -1 * $s / $this->QR[$k][$k];
                    for ($i = $k; $i < $this->m; $i++) {
                        $Q[$i][$j] += $s * $this->QR[$i][$k];
                    }
                }
            }
            --$k;
        }
        return new PHPExcel_Shared_JAMA_Matrix($Q);
    }
    public function solve($B)
    {
        if($B->getRowDimension() == $this->m) {
            if($this->isFullRank()) {
                $nx = $B->getColumnDimension();
                $X = $B->getArrayCopy();
                for ($k = 0; $k < $this->n; $k++) {
                    for ($j = 0; $j < $nx; $j++) {
                        $s = 0;
                        for ($i = $k; $i < $this->m; $i++) {
                            $s += $this->QR[$i][$k] * $X[$i][$j];
                        }
                        $s = -1 * $s / $this->QR[$k][$k];
                        for ($i = $k; $i < $this->m; $i++) {
                            $X[$i][$j] += $s * $this->QR[$i][$k];
                        }
                    }
                }
                $k = $this->n - 1;
                while (0 <= $k) {
                    for ($j = 0; $j < $nx; $j++) {
                        $X[$k][$j] /= $this->Rdiag[$k];
                    }
                    for ($i = 0; $i < $k; $i++) {
                        for ($j = 0; $j < $nx; $j++) {
                            $X[$i][$j] -= $X[$k][$j] * $this->QR[$i][$k];
                        }
                    }
                    --$k;
                }
                $X = new PHPExcel_Shared_JAMA_Matrix($X);
                return $X->getMatrix(0, $this->n - 1, 0, $nx);
            }
            throw new PHPExcel_Calculation_Exception("Can only perform operation on full-rank matrix.");
        }
        throw new PHPExcel_Calculation_Exception(PHPExcel_Shared_JAMA_Matrix::MATRIX_DIMENSION_EXCEPTION);
    }
}

?>